package com.qianfeng.springcloud.order.controller;

//
//                            _ooOoo_  
//                           o8888888o  
//                           88" . "88  
//                           (| -_- |)  
//                            O\ = /O  
//                        ____/`---'\____  
//                      .   ' \\| |// `.  
//                       / \\||| : |||// \  
//                     / _||||| -:- |||||- \  
//                       | | \\\ - /// | |  
//                     | \_| ''\---/'' | |  
//                      \ .-\__ `-` ___/-. /  
//                   ___`. .' /--.--\ `. . __  
//                ."" '< `.___\_<|>_/___.' >'"".  
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |  
//                 \ \ `-. \_ __\ /__ _/ .-` / /  
//         ======`-.____`-.___\_____/___.-`____.-'======  
//                            `=---='  
//  
//         .............................................  
//                  佛祖镇楼                  BUG辟易  
//          佛曰:  
//                  写字楼里写字间，写字间里程序员；  
//                  程序人员写程序，又拿程序换酒钱。  
//                  酒醒只在网上坐，酒醉还来网下眠；  
//                  酒醉酒醒日复日，网上网下年复年。  
//                  但愿老死电脑间，不愿鞠躬老板前；  
//                  奔驰宝马贵者趣，公交自行程序员。  
//                  别人笑我忒疯癫，我笑自己命太贱；  
//  


import com.qianfeng.springcloud.order.feign.AddressOpenfeign;
import com.qianfeng.springcloud.order.pojo.Address;
import com.qianfeng.springcloud.order.pojo.Order;
import com.qianfeng.springcloud.order.pojo.Student;
import com.qianfeng.springcloud.order.pojo.TestBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.Random;

/**
 * Created by Jackiechan on 2022/6/23 9:34
 *
 * @author Jackiechan
 * @version 1.0
 * @since 1.0
 */
@RestController
@RequestMapping("/order")
//@RefreshScope //不要忘记添加这个注解,不然数据不会发生变化,如果属性是封装到某个类的对象中,则可以不用加
public class OrderController {
    /**
     * 这种属性需要通过RefreshScope注解来刷新
     */
    @Value("${suibian.ceshi.name}")
    private String name;

    private Random random = new Random();

    private Student student;

    @Autowired
    public void setStudent(Student student) {
        this.student = student;
    }

    private AddressOpenfeign addressOpenfeign;

    @Autowired
    public void setAddressOpenfeign(AddressOpenfeign addressOpenfeign) {
        this.addressOpenfeign = addressOpenfeign;
    }

    @GetMapping("/info/{id}")
    public Order findById(@PathVariable Long id) {
        Order order = new Order();
        order.setId(id);
        order.setPrice(random.nextDouble());
        order.setItemName("打气筒" + random.nextInt());

        //我们发现我们还需要地址的数据,但是地址不在当前程序内部,在另外一个服务器的程序里面
        Address address = addressOpenfeign.findById(id);
        order.setAddress(address);
        return order;
    }

    @GetMapping("/test22222")
    public String test2222(String aaa) {
        return addressOpenfeign.test2(aaa);
    }

    @GetMapping("/test33333")
    public String test33333(String aaa, int abc) {
        return addressOpenfeign.test3(aaa, abc);
    }


    @GetMapping("/test444444")
    public Address test33333(Address address) {
        return addressOpenfeign.test4(address);
    }


    @GetMapping("/test55555")
    public String test55555(TestBean testBean) {
        return addressOpenfeign.test3(testBean.getAsdf(), testBean.getZxcv());
    }

    @PostMapping("/test666666")
    public String test666666(@RequestBody TestBean testBean) {
        return addressOpenfeign.test3(testBean.getAsdf(), testBean.getZxcv());
    }

    @GetMapping("/name")
    public String getName() {
        return name;
    }

    @GetMapping("/stu")
    public Student getStudent() {
        return student;
    }
}
